<template>
  <el-form
    class="learun-el-form-left"
    :model="formData"
    :rules="isReadOnly ? {} : rules"
    size="mini"
    labelPosition="left"
    labelWidth="100px"
    ref="form"
  >
    <el-row v-if="!loading" class="erp-supplier-assess">
      <el-col :span="24">
        <div class="learun-form-title mt-16">
          {{ $t("供货能力评估") }}
        </div>
        <div class="form_block">
          <el-form-item
            :label="$t('等级：')"
            prop="case_erp_supplierrisk_f_CapacityLevel"
            v-if="isReadOnly"
          >
            <el-tag
              v-if="formData.case_erp_supplierrisk_f_CapacityLevel == '0'"
              >{{ $t("优秀") }}</el-tag
            >
            <el-tag
              v-else-if="formData.case_erp_supplierrisk_f_CapacityLevel == '1'"
              type="success"
              >{{ $t("良好") }}</el-tag
            >
            <el-tag
              v-else-if="formData.case_erp_supplierrisk_f_CapacityLevel == '2'"
              type="info"
              >{{ $t("及格") }}</el-tag
            >
            <el-tag v-else type="danger">{{ $t("不及格") }}</el-tag>
          </el-form-item>
          <el-form-item
            :label="$t('等级选择：')"
            v-else
            prop="case_erp_supplierrisk_f_CapacityLevel"
          >
            <l-radio
              :options="case_erp_supplierrisk_f_CapacityLevelOptions"
              v-model="formData.case_erp_supplierrisk_f_CapacityLevel"
            />
          </el-form-item>
          <el-form-item
            :label="$t('评估理由：')"
            prop="case_erp_supplierrisk_f_CapacityReason"
          >
            <div v-if="isReadOnly">
              {{ formData.case_erp_supplierrisk_f_CapacityReason }}
            </div>
            <el-input
              v-else
              type="textarea"
              style="width: 500px"
              :showWordLimit="false"
              v-model="formData.case_erp_supplierrisk_f_CapacityReason"
              :placeholder="$t('please enter')"
            />
          </el-form-item>
          <el-form-item
            :label="$t('附件上传：')"
            prop="case_erp_supplierrisk_f_CapacityFile"
          >
            <el-col :span="24">
              <el-form-item
                prop="case_erp_supplierrisk_f_CapacityFile"
                labelWidth="0"
              >
                <l-upload
                  drag
                  maxSize="10"
                  sizeType="MB"
                  :limit="3"
                  showFileList="uploadTheme1"
                  :disabled="isReadOnly"
                  v-model="formData.case_erp_supplierrisk_f_CapacityFile"
                />
              </el-form-item>
            </el-col>
          </el-form-item>
        </div>
      </el-col>
      <el-col :span="24">
        <div class="learun-form-title mt-16">
          {{ $t("供货质量评估") }}
        </div>

        <div class="form_block">
          <el-form-item
            :label="$t('等级：')"
            prop="case_erp_supplierrisk_f_SupplierLevel"
            v-if="isReadOnly"
          >
            <el-tag
              v-if="formData.case_erp_supplierrisk_f_SupplierLevel == '0'"
              >{{ $t("优秀") }}</el-tag
            >
            <el-tag
              v-else-if="formData.case_erp_supplierrisk_f_SupplierLevel == '1'"
              type="success"
              >{{ $t("良好") }}</el-tag
            >
            <el-tag
              v-else-if="formData.case_erp_supplierrisk_f_SupplierLevel == '2'"
              type="info"
              >{{ $t("及格") }}</el-tag
            >
            <el-tag v-else type="danger">{{ $t("不及格") }}</el-tag>
          </el-form-item>
          <el-form-item
            :label="$t('等级选择：')"
            v-else
            prop="case_erp_supplierrisk_f_SupplierLevel"
          >
            <l-radio
              :options="case_erp_supplierrisk_f_SupplierLevelOptions"
              v-model="formData.case_erp_supplierrisk_f_SupplierLevel"
            />
          </el-form-item>
          <el-form-item
            :label="$t('评估理由：')"
            prop="case_erp_supplierrisk_f_SupplierReason"
          >
            <div v-if="isReadOnly">
              {{ formData.case_erp_supplierrisk_f_SupplierReason }}
            </div>
            <el-input
              v-else
              type="textarea"
              style="width: 500px"
              v-model="formData.case_erp_supplierrisk_f_SupplierReason"
              :placeholder="$t('please enter')"
            />
          </el-form-item>
          <el-form-item
            :label="$t('附件上传：')"
            prop="case_erp_supplierrisk_f_SupplierFile"
          >
            <l-upload
              drag
              maxSize="10"
              sizeType="MB"
              :limit="3"
              showFileList="uploadTheme1"
              :disabled="isReadOnly"
              v-model="formData.case_erp_supplierrisk_f_SupplierFile"
              :placeholder="$t('please enter')"
            />
          </el-form-item>
        </div>
      </el-col>
      <el-col :span="24">
        <div class="learun-form-title mt-16">
          {{ $t("环境与安全评估") }}
        </div>

        <div class="form_block">
          <el-form-item
            :label="$t('等级：')"
            prop="case_erp_supplierrisk_f_SafetyLevel"
            v-if="isReadOnly"
          >
            <el-tag
              v-if="formData.case_erp_supplierrisk_f_SafetyLevel == '0'"
              >{{ $t("优秀") }}</el-tag
            >
            <el-tag
              v-else-if="formData.case_erp_supplierrisk_f_SafetyLevel == '1'"
              type="success"
              >{{ $t("良好") }}</el-tag
            >
            <el-tag
              v-else-if="formData.case_erp_supplierrisk_f_SafetyLevel == '2'"
              type="info"
              >{{ $t("及格") }}</el-tag
            >
            <el-tag v-else type="danger">{{ $t("不及格") }}</el-tag>
          </el-form-item>
          <el-form-item
            :label="$t('等级选择：')"
            v-else
            prop="case_erp_supplierrisk_f_SafetyLevel"
          >
            <l-radio
              :options="case_erp_supplierrisk_f_SafetyLevelOptions"
              v-model="formData.case_erp_supplierrisk_f_SafetyLevel"
            />
          </el-form-item>
          <el-form-item
            :label="$t('评估理由：')"
            prop="case_erp_supplierrisk_f_SafetyReason"
          >
            <div v-if="isReadOnly">
              {{ formData.case_erp_supplierrisk_f_SafetyReason }}
            </div>
            <el-input
              v-else
              type="textarea"
              style="width: 500px"
              v-model="formData.case_erp_supplierrisk_f_SafetyReason"
              :placeholder="$t('please enter')"
            />
          </el-form-item>
          <el-form-item
            :label="$t('附件上传：')"
            prop="case_erp_supplierrisk_f_SafetyFile"
          >
            <l-upload
              drag
              maxSize="10"
              sizeType="MB"
              :limit="3"
              showFileList="uploadTheme1"
              :disabled="isReadOnly"
              v-model="formData.case_erp_supplierrisk_f_SafetyFile"
              :placeholder="$t('please enter')"
            />
          </el-form-item>
        </div>
      </el-col>
      <el-col :span="24">
        <div class="learun-form-title mt-16">
          {{ $t("最终评估结果") }}
        </div>
        <div class="form_block">
          <el-form-item
            :label="$t('等级：')"
            prop="case_erp_supplierrisk_f_FinalState"
            v-if="isReadOnly"
          >
            <el-tag v-if="formData.case_erp_supplierrisk_f_FinalState == '0'">
              <i class="el-icon-s-check margin_right_3"></i>{{ $t("优秀") }}
            </el-tag>
            <el-tag
              v-else-if="formData.case_erp_supplierrisk_f_FinalState == '1'"
              type="success"
            >
              <i class="el-icon-s-check margin_right_3"></i>
              {{ $t("良好") }}
            </el-tag>
            <el-tag
              v-else-if="formData.case_erp_supplierrisk_f_FinalState == '2'"
              type="info"
            >
              <i class="el-icon-s-check margin_right_3"></i>
              {{ $t("及格") }}
            </el-tag>
            <el-tag v-else type="danger">
              <i class="el-icon-s-check margin_right_3"></i>
              {{ $t("不及格") }}
            </el-tag>
          </el-form-item>
          <el-form-item
            :label="$t('等级选择：')"
            v-else
            prop="case_erp_supplierrisk_f_FinalState"
          >
            <l-radio
              :options="case_erp_supplierrisk_f_FinalStateOptions"
              v-model="formData.case_erp_supplierrisk_f_FinalState"
            />
          </el-form-item>
          <el-form-item
            :label="$t('评估理由：')"
            prop="case_erp_supplierrisk_f_FinalReason"
          >
            <div v-if="isReadOnly">
              {{ formData.case_erp_supplierrisk_f_FinalReason }}
            </div>
            <el-input
              v-else
              type="textarea"
              style="width: 500px"
              v-model="formData.case_erp_supplierrisk_f_FinalReason"
              :placeholder="$t('please enter')"
            />
          </el-form-item>
        </div>
      </el-col>
    </el-row>
  </el-form>
</template>
<script>
const api = window.$api.erpcase.supplier;
export default {
  props: {
    isReadOnly: {
      type: Boolean,
      default: false,
    },
    id: {},
    type: {},
  },
  data() {
    return {
      moduleCode: "ERP_Suppliers",
      formData: {
        case_erp_supplierrisk_f_CapacityLevel: "", // 等级选择：
        case_erp_supplierrisk_f_CapacityReason: "", // 评估理由：
        case_erp_supplierrisk_f_CapacityFile: "", // 附件上传：
        case_erp_supplierrisk_f_SupplierLevel: "", // 等级选择：
        case_erp_supplierrisk_f_SupplierReason: "", // 评估理由：
        case_erp_supplierrisk_f_SupplierFile: "", // 附件上传：
        case_erp_supplierrisk_f_SafetyLevel: "", // 等级选择：
        case_erp_supplierrisk_f_SafetyReason: "", // 等级选择：
        case_erp_supplierrisk_f_SafetyFile: "", // 附件上传：
        case_erp_supplierrisk_f_FinalState: "", // 等级选择：
        case_erp_supplierrisk_f_FinalReason: "", // 评估理由：
      },
      rules: {
        case_erp_supplierrisk_f_CapacityLevel: [
          { required: true, message: "please select：" },
        ],
        case_erp_supplierrisk_f_CapacityReason: [
          { required: true, message: "please enter：" },
        ],
        case_erp_supplierrisk_f_SupplierLevel: [
          { required: true, message: "please select：" },
        ],
        case_erp_supplierrisk_f_SupplierReason: [
          { required: true, message: "please enter：" },
        ],
        case_erp_supplierrisk_f_SafetyLevel: [
          { required: true, message: "please select：" },
        ],
        case_erp_supplierrisk_f_SafetyReason: [
          { required: true, message: "please enter：" },
        ],
        case_erp_supplierrisk_f_FinalState: [
          { required: true, message: "please select：" },
        ],
        case_erp_supplierrisk_f_FinalReason: [
          { required: true, message: "please enter：" },
        ],
      },
      loading: true,
    };
  },
  computed: {
    case_erp_supplierrisk_f_CapacityLevelOptions() {
      return [
        { label: "优秀", value: "0" },
        { value: "1", label: "良好" },
        { value: "2", label: "及格" },
        { value: "3", label: "不及格" },
      ];
    },
    case_erp_supplierrisk_f_SupplierLevelOptions() {
      return [
        { label: "优秀", value: "0" },
        { value: "1", label: "良好" },
        { value: "2", label: "及格" },
        { value: "3", label: "不及格" },
      ];
    },
    case_erp_supplierrisk_f_SafetyLevelOptions() {
      return [
        { label: "优秀", value: "0" },
        { value: "1", label: "良好" },
        { value: "2", label: "及格" },
        { value: "3", label: "不及格" },
      ];
    },
    case_erp_supplierrisk_f_FinalStateOptions() {
      return [
        { label: "优秀", value: "0" },
        { value: "1", label: "良好" },
        { value: "2", label: "及格" },
        { value: "3", label: "不及格" },
      ];
    },
  },
  created() {
    if (this.isReadOnly) {
      this.loadFormData(this.id);
    } else {
      this.loading = false;
    }
  },
  methods: {
    // Reset表单
    resetForm() {
      this.$formClear(this.$refs.form);
    },
    // 校验表单
    async validateForm() {
      if (!(await this.$formValidateWraper(this.$refs.form))) {
        return false;
      }
      return true;
    },

    // 设置表单数据
    setForm(data) {
      this.$setFormData(this.formData, data, "case_erp_supplierrisk");
    },
    // 获取表单数据
    getForm() {
      const formData = this.$getFormData(
        this.formData,
        "case_erp_supplierrisk"
      );
      formData.f_Type = this.type;
      formData.f_SupplierId = this.id;
      return formData;
    },

    async loadFormData(keyValue) {
      this.loading = true;
      const data = await this.$awaitWraper(api.getAssess(keyValue, this.type));
      if (data) {
        this.setForm(data);
        this.loading = false;
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.erp-supplier-assess .el-tag.el-tag--success {
  color: rgba(82, 196, 26, 1);
  font-size: 14px;
}
</style>